<template>
<div>
    <Form ref="EditForm" :model="FormData"  label-position="top">
        <Row :gutter="16">
            <Col :xs="24" :md="24">
            <FormItem label="变量名" prop="ConfigKey" :rules="{required: true, message:'不能为空', trigger: 'blur'}">
                <Input v-model="FormData.ConfigKey"></Input>
            </FormItem>
            </Col>
            <Col :xs="24" :md="24">
            <FormItem label="变量值" prop="ConfigValue" :rules="{required: true, message:'不能为空', trigger: 'blur'}">
                <Input v-model="FormData.ConfigValue"></Input>
            </FormItem>
            </Col>

            <Col :xs="24" :md="24">
            <FormItem label="备注" prop="ConfigInfo" :rules="{required: true, message:'不能为空', trigger: 'blur'}">
                <Input v-model="FormData.ConfigInfo"></Input>
            </FormItem>
            </Col>

        </Row>
        <Row>
            <Col>
            <FormItem>
                <Button type="primary" @click="handleSubmit()">提交</Button>
                <Button  @click="handleReset()" style="margin-left: 8px">重置</Button>
            </FormItem>
            </Col>
        </Row>

    </Form>
</div>
</template>

<script>
import then from 'thenjs';
import moment from 'moment';
import AppFrame from '../../../libs/app-frame';
export default {
    data: function() {
        return {
            State: { //数据加载状态
                IsLoadingData: false,
                IsChangeData: false
            },
            FormData: {
                OldKey:'',
                ConfigKey:'',
                ConfigValue:'',
                ConfigInfo:''
            },
            Query: {}
        }
    },
    created: function() {
        this.Query = this.$route.query;
        this.getFormData();
    },
    methods: {
        getFormData() {
            let self = this;
            self.State.IsLoadingData = true;
            let postData={
                 ConfigKey: self.Query.ConfigKey
            };
            AppFrame.Http.Post("/manage-api/system/params/getItem", postData, function(err, ret) {
                self.State.IsLoadingData = false;
                console.log(ret);
                if (ret && ret.Result == 1) {
                    self.FormData = ret.Data;
                     self.FormData.OldKey=ret.Data.ConfigKey;
                } else {
                    self.$Message.error(ret.Msg);
                }
            });
        },
        handleSubmit() {
            let self=this;
            self.$refs["EditForm"].validate((valid) => {
                if (valid) {
                    AppFrame.Http.Post("/manage-api/system/params/edit",self.FormData,function(err,ret){
                        console.log(ret);
                        if(ret && ret.Result==1){
                            self.$Message.success('保存成功');
                            self.$router.go(-1);
                        }else{
                            self.$Message.error(ret.Msg);
                        }
                    })
                } else {
                    self.$Message.error('表单验证失败!');
                }
            });
        },
        handleReset() {
            this.$refs["EditForm"].resetFields();
        }
    }
}
</script>

<style scoped>

</style>
